package com.yinhe.music.yhmusic.instrument;

import android.content.Intent;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.RelativeLayout;

import com.apkfuns.logutils.LogUtils;
import com.yinhe.music.yhmusic.R;
import com.yinhe.music.yhmusic.base.BaseModel;
import com.yinhe.music.yhmusic.base.BasePresenter;
import com.yinhe.music.yhmusic.base.BaseServiceActivity;
import com.yinhe.music.yhmusic.constants.KeyConstants;
import com.yinhe.music.yhmusic.singer.info.SingerInfoActivity;

import java.io.Serializable;
import java.util.List;

import butterknife.BindView;
/*
* 乐器
*
* */
public class InstrumentActivity extends BaseServiceActivity implements
        InstrumentListContract.IInstrumentListView {

    @BindView(R.id.recommend_music_recyclerview)
    RecyclerView mRecyclerView;
    @BindView(R.id.rl_activity_collection_radio)
    RelativeLayout mRootLayout;

    int lineCount = 3;

    InstrumentAdapter mAdapter;

    GridLayoutManager layoutManager;

    InstrumentListPresenter mPresenter;

    @Override
    public void initView() {
        mRootLayout.setBackgroundColor(getResources().getColor(R.color.background));
        setToolbar("乐器");
        showQuickControl(true);
        mPresenter.getInstrumentList();
    }

    @Override
    public int getLayoutResId() {
        return R.layout.activity_collection_radio;
    }

    @Override
    public BasePresenter getPresenter() {
        return mPresenter;
    }

    @Override
    public void initPresenter() {
        mPresenter = new InstrumentListPresenter();
        mPresenter.attachModelView(new BaseModel(), this);
    }

    @Override
    public void setInstrumentListUI(List<InstrumentSection> sectionList, int pageNum) {
        layoutManager = new GridLayoutManager(this, lineCount);
        layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                return sectionList.get(position).isHeader ? 1 : lineCount;
            }
        });
        mRecyclerView.setLayoutManager(layoutManager);
        mAdapter = new InstrumentAdapter(sectionList);
        mRecyclerView.setAdapter(mAdapter);

        mAdapter.setOnItemClickListener((adapter, view, position) -> {
            List<InstrumentSection> sections = adapter.getData();
            InstrumentSection section = sections.get(position);
            if (!section.isHeader) {
                Intent intent = new Intent(this, SingerInfoActivity.class);
                intent.putExtra(KeyConstants.KEY_INSTRUMENT, section.t);
                startActivity(intent);
            }
        });
    }
}
